Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker, cgen: fix fixed array of option with default value (related #19405) #19422

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 23, 2023

This PR fix fixed array of option with default value (related #19405).

  • Fix fixed array of option with default value.
  • Add test.
fn main() {
	mut a1 := [3]?int{init: ?int(1)}
	a1[0] = none
	a1[1] = 2
	println(a1)
	assert '${a1}' == '[Option(none), Option(2), Option(1)]'

	mut a11 := [3]?int{init: 1}
	a11[0] = none
	a11[1] = 2
	println(a11)
	assert '${a11}' == '[Option(none), Option(2), Option(1)]'

	mut a2 := [3]?int{}
	a2[0] = 1
	println(a2)
	assert '${a2}' == '[Option(1), Option(none), Option(none)]'

	a3 := [3]?int{init: ?int(index * 2)}
	println(a3)
	assert '${a3}' == '[Option(0), Option(2), Option(4)]'

	a33 := [3]?int{init: index * 2}
	println(a33)
	assert '${a33}' == '[Option(0), Option(2), Option(4)]'
}

PS D:\Test\v\tt1> v run .
[Option(none), Option(2), Option(1)]
[Option(none), Option(2), Option(1)]
[Option(1), Option(none), Option(none)]
[Option(0), Option(2), Option(4)]
[Option(0), Option(2), Option(4)]

@spytheman spytheman merged commit 9954f89 into vlang:master Sep 23, 2023
46 checks passed
@yuyi98 yuyi98 deleted the fix_array_init_with_default branch September 24, 2023 00:26
Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants